package algorithm.leetcode.q7;

import com.sun.xml.internal.ws.util.StringUtils;

/**
 * <p>整数反转</p>
 *
 * @author LiShaoWen
 * @date 2021/7/27 17:08
 */
public class Solution {
    public int reverse(int x) {
        String s = String.valueOf(x);
        String result = "";
        if (x<0 &&  s.length()>1){
            result = s.charAt(0) + new StringBuilder(s.substring(1)).reverse().toString();
        }else{
            result = new StringBuilder(s).reverse().toString();
        }
        Long l = Long.valueOf(result);
        if (l>Integer.MAX_VALUE || l<Integer.MIN_VALUE){
            return 0;
        }
        return  Integer.parseInt(String.valueOf(l));
    }

    public static void main(String[] args) {
        int i = 123;
        int reverse = new Solution().reverse(i);
        System.out.println(reverse);
    }
}
